<template>

      <el-form :inline="true">
        <el-button type="primary" @click="exportTable">{{$t('publicbtn.export')}}</el-button>
      </el-form>
      
</template>

<script>
import FileSaver from "file-saver";
import XLSX from "xlsx";
export default {
    
  data() {
    return{
   
   exportname:null
    }
  },
	watch:{
    '$route':function(to){
      console.log(to)
    }
  },

  created() {
   
  },
  mounted(){
    this.exportname=this.$router.currentRoute.name
  },
  methods: {

exportTable(){


   this.$alert( this.$t('bulletframe.ynexporttable'),  this.$t('bulletframe.exporttable'), {
          confirmButtonText: this.$t('publicbtn.determine'), 
          distinguishCancelAndClose:true,
          callback: action => {
            if(action=='confirm'){
               this.exportTableAc()
            }
          },
        });
        },
        exportTableAc(){
          var fix = document.querySelector('.el-table__fixed')
              fix = document.querySelector('.el-table__fixed-right')
          var wb;
          if(fix){
          wb = XLSX.utils.table_to_book(document.querySelector("#out-table").removeChild(fix));
                document.querySelector("#out-table").appendChild(fix);
          }else{
              wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
          }
            var wbout = XLSX.write(wb, {
                bookType: "xlsx",
                bookSST: true,
                type: "array", 
            });

              try {
                  FileSaver.saveAs(
                    new Blob([wbout],{
                    type: 'application/octet-stream'
                    }), 
                  this.exportname+'.xlsx'
                    );
              } catch (e) { 
                if (typeof console !== 'undefined') console.log(e, wbout)
                  
              }
         return wbout
        }

  },

};
</script>

<style scoped>
</style>